package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.*;
import com.hljx.entity.AccountingUnitWeight;
import com.hljx.service.AccountingUnitWeightService;
import com.hljx.vo.AccountingVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 核算单元权重配置表 前端控制器
 * </p>
 *
 * @author gx
 * @since 2023-10-07
 */
@RestController
@RequestMapping("/accountingUnitWeight")
@Tag(name = "核算单元权重配置")
public class AccountingUnitWeightController {

    @Autowired
    AccountingUnitWeightService service;

    @Operation(summary = "查询该核算周期未添加权重的核算单元")
    @GetMapping("/listAccountingVO")
    public Result<List<AccountingVO>> listAccountingVO(@RequestParam("assessmentCycleId") Long assessmentCycleId) {
        return Result.success(service.listAccountingVO(assessmentCycleId));
    }

    @Operation(summary = "保存核算单元权重")
    @PostMapping("/saveAccountingUnitWeight")
    public Result<Boolean> saveAccountingUnitWeight(@RequestBody AccountingUnitWeightDTO accountingUnitWeightDTO) {
        return Result.success(service.saveAccountingUnitWeight(accountingUnitWeightDTO));
    }


    @Operation(summary = "分页查询核算单元权重配置")
    @PostMapping("/listAccountingUnitWeightByPage")
    public Result<IPage<AccountingUnitWeight>> listAccountingUnitWeightByPage(@RequestBody AccountingUnitWeightPageDTO accountingUnitWeightPageDTO) {
        return Result.success(service.listAccountingUnitWeightByPage(accountingUnitWeightPageDTO));
    }

    @Operation(summary = "归档状态  0是未归档1是已归档")
    @GetMapping("/isFile")
    public Result<Integer> isFile(@RequestParam("id") Long id) {
        return Result.success(service.isFile(id));
    }

    @Operation(summary = "编辑核算单元权重")
    @PostMapping("/updateAccountingUnitWeight")
    public Result<Boolean> updateAccountingUnitWeight(@RequestBody AccountingUnitWeightDTO accountingUnitWeightDTO) {
        return Result.success(service.updateAccountingUnitWeight(accountingUnitWeightDTO));
    }

    @Operation(summary = "继承核算单元权重")
    @PostMapping("/inheritAccountingUnitWeight")
    public Result<Boolean> inheritAccountingUnitWeight(@RequestBody InheritAccountingUnitWeightDTO inheritAccountingUnitWeightDTO) {
        return Result.success(service.inheritAccountingUnitWeight(inheritAccountingUnitWeightDTO));
    }

    @Operation(summary = "导出")
    @PostMapping("/export")
    public void export(@RequestBody ExportAccountingUnitWeight dto, HttpServletResponse response) throws ClassNotFoundException {
        service.export(dto,response);
    }

}
